package de.wbh.gwt.form.layouter.shared.place;

import java.util.Iterator;

import com.google.common.base.Splitter;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

public class EditPlace extends Place {

	public static class Tokenizer implements PlaceTokenizer<EditPlace> {
		@Override
		public EditPlace getPlace(String token) {
			String efdName = null;
			String pdfName = null;
			String confName = null;
			token = token.substring(1, token.length() - 1);
			for (String arg : Splitter.on(",").split(token)) {
				Iterator<String> argParts = Splitter.on("=").split(arg).iterator();
				String key = argParts.next();
				String value = argParts.next();
				if ("efd".equals(key)) {
					efdName = value;
				} else if ("pdf".equals(key)) {
					pdfName = value;
				} else if ("conf".equals(key)) {
					confName = value;
				}
			}
			return new EditPlace(efdName, pdfName, confName);
		}

		@Override
		public String getToken(EditPlace place) {
			return "(pdf=" + place.pdfName + ",efd=" + place.efdName + ",conf=" + place.configurationName + ")";
		}
	}

	private final String efdName;
	private final String pdfName;
	private final String configurationName;

	public EditPlace(String efdName, String pdfName, String configurationName) {
		this.efdName = efdName;
		this.pdfName = pdfName;
		this.configurationName = configurationName;
	}

	public String getConfigurationName() {
		return this.configurationName;
	}

	public String getEfdName() {
		return this.efdName;
	}

	public String getPdfName() {
		return this.pdfName;
	}

}
